package cn.itcast.tanhua.mytanhuadubboservice.api;

import cn.itcast.tanhua.mytanhuadubbointerface.api.CheckApi;
import cn.itcast.tanhua.pojo.Publish;

import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;


/**
 * @author 陈功炳
 * @since 2021/12/10 11:15
 */
@Service
public class CheckApiImpl implements CheckApi {
    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public String check(String pid, String checkResult) {

        if (checkResult.equals("1")){
            //修改条件
            //审核后通过，修改状态为1 -> 通过
            Query query = Query.query(Criteria.where("pid").is(pid));
            Update update = new Update();
            update.set("state",1);
            this.mongoTemplate.updateFirst(query,update,Publish.class);
            return "审核通过";
        }else if (checkResult.equals("2")){
            //修改条件
            Query query = new Query(Criteria.where("pid").is(pid));
            Update update = new Update();
            update.set("state",-1);
            //审核后不通过，修改状态为-1 -> 不通过
            mongoTemplate.updateFirst(query,update,Publish.class);
            return "审核不通过,请检查动态信息是否正规";
        }
        return "审核出错";
    }
}
